<?php
namespace Admin\Controller;
use Think\Controller;
class ArtypeController extends CommonController {
	function articlelist(){
		$info = D('Artype')->where('type = 1')->select();
		$this->assign('show',$info);
		$this->display();
		}
	function goodslist(){
		$info = D('Artype')->where('type = 2')->select();
		$this->assign('show',$info);
		$this->display();
		}
	function pagelist(){
		$info = D('Artype')->where('type = 3')->select();
		$this->assign('show',$info);
		$this->display();
		}
		

	function add(){
		if(empty($_POST)){
			
			$type = $_GET['cate'];
			if($type == 1){
				$_SESSION['type'] = 1;
				}
			if($type == 2){
				$_SESSION['type'] = 2;
				}
			if($type == 3){
				$_SESSION['type'] = 3;
				}
			$this->display();
			}else{
				if(empty($_POST['artype_name'])){
					$this->error("未填写分类名称");
					}else{
						if(empty($_POST['status'])){
							$_POST['status'] = 0;
							}
						$_POST['type'] = $_SESSION['type'];
						$add = D('Artype')->add($_POST);
						if($add){
							$this->success('添加成功');
							}else{
								$this->error('添加失败');
								}
						}
				
				}
			}
	function addpage(){
		if(empty($_POST)){
			$type = $_GET['cate'];
			if($type == 1){
				$_SESSION['type'] = 1;
				}
			if($type == 2){
				$_SESSION['type'] = 2;
				}
			if($type == 3){
				$_SESSION['type'] = 3;
				}
			$this->display();
			}else{
				if(empty($_POST['artype_name'])){
					$this->error("未填写分类名称");
					}else{
						$_POST['type'] = $_SESSION['type'];
						
						$add = D('Artype')->add($_POST);
						if($add){
							$this->success('添加成功');
							}else{
								$this->error('添加失败');
								}
						}
				}
		}
	function update(){
		$id['id'] = $_GET['id'];
		if(empty($_POST)){
			$info = D('Artype')->where($id)->select();
			$this->assign('show',$info);
			$this->display();
			}else{
				if(empty($_POST['status'])){
					$_POST['status'] = 0;
					}
				$info = D('Artype')->where($id)->save($_POST);
				if($info){
					$this->success('数据修改成功');
					}else{
						$this->error('数据修改失败');
						}
				}
		}
		
	function updatepage(){
		$id['id'] = $_GET['id'];
		if(empty($_POST)){
			$info = D('Artype')->where($id)->select();
			$this->assign('show',$info);
			$this->display();
			}else{
				if(empty($_POST['status'])){
					$_POST['status'] = 0;
					}
				$info = D('Artype')->where($id)->save($_POST);
				if($info){
					$this->success('数据修改成功');
					}else{
						$this->error('数据修改失败');
						}
				}
		}
		
	function delete(){
		$where['id']=$_GET['id'];
		$dele = D('Artype')->where($where)->delete();
			if($dele){
				$this->success('删除成功');
				}else{
					$this->error('删除失败');
			}
		}
	}